package com.pompom.matchcrawler.types;

import javax.management.RuntimeErrorException;

@com.assembla.gummy.database.info.DataBaseEntity(tableName = "MATCH_STAT")
public class TOMatchStat {
    @com.assembla.gummy.database.info.DataBaseField(columnName = "MATCHID")
    private Long matchid; 
    @com.assembla.gummy.database.info.DataBaseField(columnName = "COMPIDX")
    private Byte compidx;
    @com.assembla.gummy.database.info.DataBaseField(columnName = "COMPSTATUS")
    private Integer compstatus;

    public TOMatchStat() {
    }
 
    public void setMatchid(Long matchid) {
        this.matchid = matchid;
    }
 

    public void setCompidx(Byte compidx) {
        this.compidx = compidx;
    }

    public void setCompstatus(Integer compstatus) {
        this.compstatus = compstatus;
    }

    public Long getMatchid() {
        return matchid;
    }

    

    public Byte getCompidx() {
        return compidx;
    }

    public Integer getCompstatus() {
        return compstatus;
    }
    
    

    public static final int TOP_TIER1=0,
    						TOP_TIER2=1,
    						TOP_TIER3=2,
    						MID_TIER1=3,
    						MID_TIER2=4,
    						MID_TIER3=5,
    						BOT_TIER1=6,
    						BOT_TIER2=7,
    						BOT_TIER3=8,
    						ANCIENT_BOT=9,
    						ANCIENT_TOP=10;
    /**
     * 
     * @param radiant 
     * @param pos 0-top 1-mid 2-bot
     * @param ms
     * @return true se ainda ta viva
     */			
    public boolean getTowerStatus (boolean radiant,  int pos,TOMatchStat[] ms)
    {
    	if (ms.length!=4)
    		return true;
    	if (radiant)
    	{
    		
    		for (int i=0;i<ms.length;i++)
    		{
    			if (ms[i].compidx==3) //tower status radiant
    			{
    				return ( ( ms[i].compstatus & (1<<(pos )))!=0);
    			}
    		}    		    		
    	}
    	else
    	{
    		for (int i=0;i<ms.length;i++)
    		{
    			if (ms[i].compidx==2) //tower status dire
    			{
    				return ( ( ms[i].compstatus & (1<<(pos )))!=0);
    			}
    		}   
    	}
    	
    	throw (new RuntimeErrorException(new Error(), "Peem"));
    }
    
    
    public static final int TOP_MELEE=0,
    		TOP_RANGED=1,
    		MIDDLE_MELEE=2,
    		MIDDLE_RANGED=3, 
    		BOTTOM_MELEE=4,
    		BOTTOM_RANGED=5;
    public boolean getBarrackStatus (boolean radiant,  int pos,TOMatchStat[] ms)
    {
    	if (ms.length!=4)
    		return true;
    	
    	if (radiant)
    	{
    		
    		for (int i=0;i<ms.length;i++)
    		{
    			if (ms[i].compidx==1) //barrack status radiant
    			{
    				return ( ( ms[i].compstatus & (1<<(pos )))!=0);
    			}
    		}    		    		
    	}
    	else
    	{
    		for (int i=0;i<ms.length;i++)
    		{
    			if (ms[i].compidx==0) //barrack status dire
    			{
    				return ( ( ms[i].compstatus & (1<<(pos )))!=0);
    			}
    		}   
    	}
    	
    	throw (new RuntimeErrorException(new Error(), "Peem"));
    }
    
}
